<%@ page import="fi.hell.lunchit.Round" %>
<%@ page import="fi.hell.lunchit.User" %>

<g:set var="currentRound" value="${Round.currentRound()}" />
<g:set var="currentVote" value="${Round.currentVote(currentRound)}" />
<g:set var="loggedInUser" value="${User.getLoggedInUser()}" />

<html>
  <head>
    <title>LunchIT <g:if test="${loggedInUser}">- ${loggedInUser.company?.name}</g:if></title>
    <meta name="layout" content="main" />
  </head>
  <body>
  <g:render template="panels" model="[loggedInUser:loggedInUser, currentRound:currentRound, currentVote:currentVote]" />

  <div id="pageBody">
    <h1>LunchIT <g:if test="${loggedInUser}">- ${loggedInUser.company?.name}</g:if></h1>
    <p><g:message code="rules" default="Voting starts at 8:00am and ends at 11:00am. Click logo to vote." /></p>

  <g:if test="${currentRound?.confirmed && !currentRound?.selection}">
    <h3 id="currentVote"><g:message code="makeFinalSelection" default="Make your final selection by clicking the restaurant icon where you're going to eat for sure!" /></h3>
  </g:if>
  <g:elseif test="${currentVote > 0 && !currentRound?.confirmed}">
    <h3 id="currentVote"><g:message code="currentVote" args="${[currentVote]}" default="Next vote will give {0} points" /></h3>
  </g:elseif>
  <g:elseif test="${currentVote == 0 && !currentRound?.confirmed}">
    <h3 id="currentVote"><g:message code="notVotesLeft" default="You have no votes left. Confirm your votes." /></h3>
  </g:elseif>

  <g:if test="${!currentRound?.selection && params.view != 'stats'}">
    <g:orderedRestaurantList sort="${params.sort}" order="${params.order}" currentVote="${currentVote}" currentRound="${currentRound}" />
  </g:if>
  <g:else>
    <g:render template="results" model="[loggedInUser:loggedInUser]" />
  </g:else>

</div>
</body>
</html>
